//
//  YMineViewController.m
//  shijianpinggu
//
//  Created by apple on 2016/12/23.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "YMineViewController.h"
#import "YMineCollectionViewCell.h"
#import "YHistoryViewController.h"
#import "YFunctionViewController.h"
#import "YManagerViewController.h"
#import "YAboutViewController.h"
#import <MeiQiaSDK/MeiQiaSDK.h>
#import <Meiqia/MQChatViewManager.h>


@interface YMineViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contViewHeigh;
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UIImageView *backImageV;
@property (weak, nonatomic) IBOutlet UIImageView *headImageV;
@property (weak, nonatomic) IBOutlet UILabel *nameLable;

@property(nonatomic,strong)NSArray *imageAr;
@property(nonatomic,strong)NSArray *nameAr;

@end

@implementation YMineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.title = @"个人中心";
    
    [self.collectionView registerNib:[UINib nibWithNibName:@"YMineCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"minecocell"];
    
//    [[YNavigationController new].navigationBar  setBackgroundImage:[UIImage imageNamed:@"wo_top"] forBarMetrics:UIBarMetricsDefault];
    
        // 设置状态栏
    [UIApplication sharedApplication].statusBarStyle = UIBarStyleBlackOpaque;
    
//    //控件切圆角
//    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.headImageV.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:self.headImageV.bounds.size];
//    CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
//    //设置大小
//    maskLayer.frame = self.headImageV.bounds;
//    //设置图形样子
//    maskLayer.path = maskPath.CGPath;
//    self.headImageV.layer.mask = maskLayer;
    
    
    self.imageAr = [[NSArray alloc] initWithObjects:@"lishi",@"gongneng",@"guanli",@"anquan", nil];
    self.nameAr = [[NSArray alloc] initWithObjects:@"历史记录",@"设置功能",@"在线支持",@"关于安全感", nil];
    self.nameLable.text = @"";
    
    
    self.contViewHeigh.constant = 300+35+110*2;

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
#warning Incomplete implementation, return the number of sections
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of items
    return 4;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    YMineCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"minecocell" forIndexPath:indexPath];
    
    cell.imageV.image = [UIImage imageNamed:self.imageAr[indexPath.row]];
    cell.nameLabel.text = self.nameAr[indexPath.row];
    
    return cell;
}
#pragma mark ---- UICollectionViewDelegateFlowLayout

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return (CGSize){(self.view.frame.size.width-1)/2,(self.collectionView.frame.size.height-1)/2};
}


- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}


- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 1.f;
}


- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 1.f;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    //self.hidesBottomBarWhenPushed = YES;
    if (indexPath.row == 0) {
        [self showViewController:[YHistoryViewController new] sender:nil];
    }else if(indexPath.row == 1){
        [self showViewController:[YFunctionViewController new] sender:nil];
    }else if(indexPath.row == 2){

        #pragma mark - 美洽
        MQChatViewManager *chatViewManager = [[MQChatViewManager alloc] init];
        NSString *userid = [[NSUserDefaults standardUserDefaults] objectForKey:@"userid"];
        [chatViewManager setLoginCustomizedId:userid];
//        [chatViewManager setLoginMQClientId:userid];
        //开启同步消息
        [chatViewManager enableSyncServerMessage:true];
        [chatViewManager pushMQChatViewControllerInViewController:self];
//        [self showViewController:[YManagerViewController new] sender:nil];
    }else if(indexPath.row == 3){
        [self showViewController:[YAboutViewController new] sender:nil];
    }
    //self.hidesBottomBarWhenPushed = NO;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/



@end
